﻿<Window x:Class="SecurityAdminSuite.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:SecurityAdminSuite"      
        xmlns:dialogs="clr-namespace:SecurityAdminSuite.Dialogs"
        xmlns:sf="clr-namespace:SecurityFramework;assembly=Security.Framework.Base"
        xmlns:clr="clr-namespace:System;assembly=mscorlib"
        Title="Security Admin Suite for Memory Lifter" Height="600" Width="800"
        KeyDown="UserControl_KeyDown"
        local:Facade.Item="{Binding}" 
        Icon="/Images/App.png" WindowStartupLocation="CenterScreen" Closing="Window_Closing">
    <Window.Resources>

        <Style TargetType="{x:Type TextBox}">
            <Setter Property="VerticalAlignment" Value="Center"/>

        </Style>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="VerticalAlignment" Value="Center"/>
        </Style>


        <DataTemplate DataType="{x:Type local:TypeInformation}">
            <ScrollViewer TextElement.Foreground="Black">


                <StackPanel Grid.IsSharedSizeScope="True">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition SharedSizeGroup="Col1"/>
                            <ColumnDefinition SharedSizeGroup="Col2"/>
                            <ColumnDefinition SharedSizeGroup="Col3"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock FontWeight="Bold" Text="Permission" Grid.Column="0"/>
                        <TextBlock Margin="10,0,0,0" FontWeight="Bold" Text="Allowed" Grid.Column="1"/>
                        <TextBlock Margin="10,0,0,0" FontWeight="Bold" Text="Inherited" Grid.Column="2"/>
                    </Grid>
                    <ItemsControl Margin="0,10,0,0" ItemsSource="{Binding Permissions}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid Margin="0,5,0,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition SharedSizeGroup="Col1"/>
                                        <ColumnDefinition SharedSizeGroup="Col2"/>
                                        <ColumnDefinition SharedSizeGroup="Col3"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock  Foreground="Black"  Text="{Binding PermissionInfo.PermissionName}" Grid.Column="0"/>
                                    <CheckBox  Margin="10,0,0,0" IsChecked="{Binding Access}" Grid.Column="1"/>
                                    <CheckBox  Margin="10,0,0,0" IsChecked="{Binding IsInherited}" IsEnabled="False" Grid.Column="2"/>

                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                    <Button  Margin="0,10,0,0" 
                                    Command="{Binding Path=(local:Facade.Item).ResetTypePermissionCommand , RelativeSource={RelativeSource Self}}"
                                    CommandParameter="{Binding}">
                        <Button.Content>
                            <TextBlock Text="Reset" TextAlignment="Center"/>
                        </Button.Content>
                    </Button>
                </StackPanel>
            </ScrollViewer>
        </DataTemplate>
        <DataTemplate DataType="{x:Type local:ObjectInformation}">
            <ScrollViewer TextElement.Foreground="Black">
                <StackPanel Grid.IsSharedSizeScope="True">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition SharedSizeGroup="Col1"/>
                            <ColumnDefinition SharedSizeGroup="Col2"/>
                            <ColumnDefinition SharedSizeGroup="Col3"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock FontWeight="Bold" Text="Permission" Grid.Column="0"/>
                        <TextBlock Margin="10,0,0,0" FontWeight="Bold" Text="Allowed" Grid.Column="1"/>
                        <TextBlock Margin="10,0,0,0" FontWeight="Bold" Text="Inherited" Grid.Column="2"/>
                    </Grid>
                    <ItemsControl Margin="0,10,0,0" ItemsSource="{Binding Permissions}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid Margin="0,5,0,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition SharedSizeGroup="Col1"/>
                                        <ColumnDefinition SharedSizeGroup="Col2"/>
                                        <ColumnDefinition SharedSizeGroup="Col3"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Foreground="Black"  Text="{Binding PermissionInfo.PermissionName}" Grid.Column="0"/>
                                    <CheckBox  Margin="10,0,0,0" IsChecked="{Binding Access}" Grid.Column="1"/>
                                    <CheckBox IsEnabled="False"  Margin="10,0,0,0" IsChecked="{Binding IsInherited}" Grid.Column="2"/>
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                    <Button  Margin="0,10,0,0" 
                                    Command="{Binding Path=(local:Facade.Item).ResetObjectPermissionCommand , RelativeSource={RelativeSource Self}}"
                                    CommandParameter="{Binding}">
                        <Button.Content>
                            <TextBlock Text="Reset" TextAlignment="Center"/>
                        </Button.Content>
                    </Button>
                </StackPanel>
            </ScrollViewer>
        </DataTemplate>
        <HierarchicalDataTemplate DataType="{x:Type local:DicInfo}" ItemsSource="{Binding Chapters}">
            <StackPanel Orientation="Horizontal">
                <!--<Image Source="pack://siteOfOrigin:,,,/Images/dictionary.png" Width="10" Height="10"/>-->
                <Image Source="Images\dictionary.png" Width="10" Height="10" />
                <TextBlock Text="{Binding Path=Name}"/>
            </StackPanel>
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate DataType="{x:Type local:ChapterInfo}" ItemsSource="{Binding Cards}">
            <StackPanel Orientation="Horizontal">
                <!--<Image Source="pack://siteOfOrigin:,,,/Images/chapter.png" Width="10" Height="10"/>-->
                <Image Source="Images\chapter.png" Width="10" Height="10" />
                <TextBlock Text="{Binding Path=Name}"/>
            </StackPanel>
        </HierarchicalDataTemplate>
        <DataTemplate DataType="{x:Type local:CardInfo}">
            <StackPanel Orientation="Horizontal">
                <!--<Image Source="pack://siteOfOrigin:,,,/Images/card.png" Width="10" Height="10"/>-->
                <Image Source="Images\card.png" Width="10" Height="10" />
                <TextBlock Text="{Binding Path=Name}"/>
            </StackPanel>
        </DataTemplate>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="24" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <Menu Grid.Row="0" x:Name="menuMain">
            <MenuItem Header="File">
                <MenuItem Header="Exit" x:Name="menuItemExit" Click="menuItemExit_Click" />
            </MenuItem>
            <MenuItem Header="Help">
                <MenuItem Header="About" x:Name="menuItemAbout" Click="menuItemAbout_Click" />
            </MenuItem>
        </Menu>

        <TabControl x:Name="tabControlMain" Grid.Row="1" SelectionChanged="TabControl_SelectionChanged">
            <TabItem Header="Groups" >
                <DockPanel >
                    <DockPanel DockPanel.Dock="Left" MinWidth="250" Margin="0,0,10,0">
                        <Grid  DockPanel.Dock="Top" Margin="0,0,0,5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="Filter: " Foreground="Black"/>
                            <TextBox Grid.Column="1" Text="{Binding GroupnameFilter,UpdateSourceTrigger=PropertyChanged}"/>
                        </Grid>
                        <ListBox x:Name="lbGroups"                      
                         DockPanel.Dock="Top"  
                         SelectedItem="{Binding Path=ActualGroup}"
                         ItemsSource="{Binding Path=Groups}">
                            <ListBox.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Header="Add new group"
                                                  Command="{Binding Path=(local:Facade.Item).AddNewGroupCommand,RelativeSource={RelativeSource Self}}"
                                                  CommandParameter="{Binding}"/>
                                </ContextMenu>
                            </ListBox.ContextMenu>
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ContextMenu>
                                            <ContextMenu>
                                                <MenuItem Header="Delete"
                                                  Command="{Binding Path=(local:Facade.Item).RemoveGroupCommand,RelativeSource={RelativeSource Self}}"
                                                  CommandParameter="{Binding}"/>
                                                <MenuItem Header="Rename Group"
                                                  Command="{Binding Path=(local:Facade.Item).RenameGroupCommand,RelativeSource={RelativeSource Self}}"
                                                  CommandParameter="{Binding}"/>
                                                <Separator/>
                                                <MenuItem Header="Add New Group"
                                                  Command="{Binding Path=(local:Facade.Item).AddNewGroupCommand,RelativeSource={RelativeSource Self}}"
                                                  CommandParameter="{Binding}"/>
                                            </ContextMenu>
                                        </Grid.ContextMenu>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="30"/>
                                            <ColumnDefinition Width="200"/>
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition/>
                                        </Grid.RowDefinitions>
                                        <!--<Image Width="15" Height="15" Source="pack://siteoforigin:,,,/Images/Group.png" Grid.Row="0" Grid.Column="0"/>-->
                                        <Image Width="15" Height="15" Source="Images\Group.png" Grid.Row="0" Grid.Column="0"/>
                                        <TextBlock Text="{Binding Name}" Grid.Row="0" Grid.Column="1"/>
                                    </Grid>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </DockPanel>

                    <ScrollViewer Padding="2" VerticalScrollBarVisibility="Auto">
                        <DockPanel DataContext="{Binding ElementName=lbGroups,Path=SelectedItem}" 
                           Visibility="{Binding ElementName=lbGroups,Path=SelectedItem,Converter={x:Static local:Converters.Null2VisibilityConverter}}"
                           Margin="0,5,0,0" >
                            <Expander DockPanel.Dock="Top"  Margin="0,5,0,0" Padding="5" IsExpanded="True" BorderThickness="1" BorderBrush="Silver">
                                <Expander.Header>Members</Expander.Header>
                                <ItemsControl BorderThickness="1" BorderBrush="Black">
                                    <ScrollViewer MaxHeight="400">
                                        <ItemsControl MinHeight="40" Padding="5" Background="White">
                                            <ItemsControl.ContextMenu>
                                                <ContextMenu>
                                                    <MenuItem Header="Add User"
                                              Command="{Binding Path= (local:Facade.Item).AddUserToActualGroupCommand,RelativeSource={RelativeSource Self}}"/>
                                                </ContextMenu>
                                            </ItemsControl.ContextMenu>
                                            <ItemsControl.ItemsSource>
                                                <MultiBinding Converter="{x:Static local:Converters.Group2MembersConverter}">
                                                    <Binding/>
                                                    <Binding Path="(local:Facade.Item)" RelativeSource="{RelativeSource Self}"/>
                                                </MultiBinding>
                                            </ItemsControl.ItemsSource>
                                            <ItemsControl.ItemTemplate>

                                                <DataTemplate>
                                                    <StackPanel Orientation="Horizontal">
                                                        <StackPanel.ContextMenu>
                                                            <ContextMenu>
                                                                <MenuItem Header="Remove User"
                                                          Command="{Binding Path=(local:Facade.Item).RemoveUserFromActualGroupCommand,RelativeSource={RelativeSource Self}}"
                                                          CommandParameter="{Binding}"/>
                                                            </ContextMenu>
                                                        </StackPanel.ContextMenu>
                                                        <!--<Image Width="15" Height="15" Margin="5,0,0,0" Source="pack://siteOfOrigin:,,,/Images/user.png" />-->
                                                        <Image Width="15" Height="15" Margin="5,0,0,0" Source="Images\user.png" />
                                                        <TextBlock Margin="2" Text="{Binding User.Account, ValidatesOnExceptions=True}">
                                                            <TextBlock.Style>
                                                                <Style TargetType="{x:Type TextBlock}">
                                                                    <Style.Triggers>
                                                                        <Trigger Property="IsMouseOver" Value="True">
                                                                            <Setter Property="Foreground" Value="Blue" />
                                                                        </Trigger>
                                                                    </Style.Triggers>
                                                                </Style>
                                                            </TextBlock.Style>
                                                        </TextBlock>
                                                    </StackPanel>
                                                </DataTemplate>
                                            </ItemsControl.ItemTemplate>
                                            <ItemsControl.ItemsPanel>
                                                <ItemsPanelTemplate>
                                                    <WrapPanel Orientation="Horizontal">

                                                    </WrapPanel>
                                                </ItemsPanelTemplate>
                                            </ItemsControl.ItemsPanel>

                                        </ItemsControl>
                                    </ScrollViewer>
                                </ItemsControl>
                            </Expander>
                            <Expander x:Name="expGroupTypePermission" Expanded="expGroupTypePermission_Expanded"  DockPanel.Dock="Top" Header="Type Permissions" Margin="0,5,0,0" Padding="5"  IsExpanded="True" BorderBrush="Silver" BorderThickness="1">
                                <DockPanel>
                                    <ListBox x:Name="lbTypes" 
                                         DockPanel.Dock="Left" 
                                         Margin="0,0,5,0"
                                         Width="250"
                                         MinHeight="200" 
                                         BorderBrush="Black"
                                         BorderThickness="1"
                                         Background="White"
                                         SelectedItem="{Binding Path=(local:Facade.Item).ActualType,RelativeSource={RelativeSource Self}}"
                                         ItemsSource="{Binding Path=(local:Facade.Item).SecurityFramework.Types,RelativeSource={RelativeSource Self}}" Loaded="lbTypes_Loaded">
                                        <ListBox.ItemTemplate>
                                            <DataTemplate>
                                                <StackPanel>
                                                    <!--<TextBlock x:Name="PART_Text" Text="{Binding Name}">-->
                                                    <TextBlock  x:Name="PART_Text">


                                                    </TextBlock>

                                                </StackPanel>
                                                <DataTemplate.Triggers>
                                                    <DataTrigger Binding="{Binding Name}" Value="MLifter.DAL.DB.DbDictionaries">
                                                        <Setter TargetName="PART_Text" Property="Text" Value="learning modules - general settings"/>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Name}" Value="MLifter.DAL.DB.DbDictionary">
                                                        <Setter TargetName="PART_Text" Property="Text" Value="learning module - specific settings"/>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Name}" Value="MLifter.DAL.DB.DbChapters">
                                                        <Setter TargetName="PART_Text" Property="Text" Value="chapters - general settings"/>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Name}" Value="MLifter.DAL.DB.DbChapter">
                                                        <Setter TargetName="PART_Text" Property="Text" Value="chapter - specific settings"/>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Name}" Value="MLifter.DAL.DB.DbCards">
                                                        <Setter TargetName="PART_Text" Property="Text" Value="cards - general settings"/>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Name}" Value="MLifter.DAL.DB.DbCard">
                                                        <Setter TargetName="PART_Text" Property="Text" Value="card - specific settings"/>
                                                    </DataTrigger>
                                                </DataTemplate.Triggers>
                                            </DataTemplate>
                                        </ListBox.ItemTemplate>
                                    </ListBox>
                                    <ContentPresenter                
                                Content="{Binding Path=(local:Facade.Item).ActualTypePermissionInformation,RelativeSource={RelativeSource Self}}"/>
                                </DockPanel>
                            </Expander>
                            <Expander x:Name="expGroupObjectPermission" Expanded="expGroupObjectPermission_Expanded" DockPanel.Dock="Top" Header="Object Permissions" Margin="0,5,0,0"  Padding="5"  IsExpanded="False" BorderBrush="Silver" BorderThickness="1">
                                <DockPanel>
                                    <TreeView DockPanel.Dock="Left" 
                                     Margin="0,0,5,0"
                                     MinHeight="40"
                                     BorderBrush="Black"
                                     BorderThickness="1"
                                     Background="White"
                                     Width="250"
                                     SelectedItemChanged="TreeView_SelectedItemChanged" 
                                     ItemsSource="{Binding Path=(local:Facade.Item).Dictionaries,RelativeSource={RelativeSource Self}}" Name="tvGroupsObjectPermissions" />
                                    <ContentPresenter x:Name="groupObjectPermissionsPresenter" Content="{Binding Path=(local:Facade.Item).ActualObjectPermissionInformation,RelativeSource={RelativeSource Self}}"/>
                                </DockPanel>
                            </Expander>
                            <ContentControl></ContentControl>
                        </DockPanel>
                    </ScrollViewer>
                </DockPanel>
            </TabItem>
            <TabItem Header="Users">

                <DockPanel>
                    <DockPanel DockPanel.Dock="Left" MinWidth="250" Margin="0,0,10,0">
                        <Grid  DockPanel.Dock="Top" Margin="0,0,0,5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="Filter: " Foreground="Black"/>
                            <TextBox Grid.Column="1" Text="{Binding UsernameFilter,UpdateSourceTrigger=PropertyChanged}"/>
                        </Grid>
                        <ListBox DockPanel.Dock="Top"
                         SelectedItem="{Binding Path=ActualUser}"
                         x:Name="lbUsers" ItemsSource="{Binding Path=Users}" Loaded="lbUsers_Loaded">
                            <ListBox.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Header="Add new user"
                                                  Command="{Binding Path=(local:Facade.Item).AddNewUserCommand,RelativeSource={RelativeSource Self}}"
                                                  CommandParameter="{Binding}"/>
                                    <MenuItem Header="Import user"
                                                  Command="{Binding Path=(local:Facade.Item).ImportNewUserCommand,RelativeSource={RelativeSource Self}}"
                                                  CommandParameter="{Binding}"/>
                                </ContextMenu>
                            </ListBox.ContextMenu>
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ContextMenu>
                                            <ContextMenu>
                                                <MenuItem Header="Delete"
                                                  Command="{Binding Path=(local:Facade.Item).RemoveUserCommand,RelativeSource={RelativeSource Self}}"
                                                  CommandParameter="{Binding}"/>
                                                <MenuItem Header="Rename User"
                                                  Command="{Binding Path=(local:Facade.Item).RenameUserCommand,RelativeSource={RelativeSource Self}}"
                                                  CommandParameter="{Binding}"/>
                                                <MenuItem Header="Change User Authentification"
                                                  Command="{Binding Path=(local:Facade.Item).ChangeUserPasswordCommand,RelativeSource={RelativeSource Self}}"
                                                  CommandParameter="{Binding}"/>
                                                <Separator/>
                                                <MenuItem Header="Add New User"
                                                  Command="{Binding Path=(local:Facade.Item).AddNewUserCommand,RelativeSource={RelativeSource Self}}"
                                                  CommandParameter="{Binding}"/>
                                                <MenuItem Header="Import user"
                                                  Command="{Binding Path=(local:Facade.Item).ImportNewUserCommand,RelativeSource={RelativeSource Self}}"
                                                  CommandParameter="{Binding}"/>
                                            </ContextMenu>
                                        </Grid.ContextMenu>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="30"/>
                                            <ColumnDefinition Width="200" Name="UserName"/>
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition/>
                                            <RowDefinition/>
                                        </Grid.RowDefinitions>
                                        <!--<Image Width="15" Height="15" Source="pack://siteoforigin:,,,/Images/User.png" Grid.Row="0" Grid.Column="0"/>-->
                                        <Image Width="15" Height="15" Source="Images\User.png" Grid.Row="0" Grid.Column="0"/>
                                        <TextBlock Text="{Binding User.Account}" Grid.Row="0" Grid.Column="1"/>
                                    </Grid>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </DockPanel>

                    <ScrollViewer Padding="2" VerticalScrollBarVisibility="Auto">
                        <DockPanel DataContext="{Binding ElementName=lbUsers,Path=SelectedItem}" 
                           Visibility="{Binding ElementName=lbUsers,Path=SelectedItem,Converter={x:Static local:Converters.Null2VisibilityConverter}}"
                           Margin="0,5,0,0" >

                            <Expander DockPanel.Dock="Top"  Margin="0,5,0,0" Padding="5" IsExpanded="True" BorderThickness="1" BorderBrush="Silver">
                                <Expander.Header>Group Membership</Expander.Header>
                                <ItemsControl                             
                            MinHeight="40" 
                            Padding="5" 
                            Background="White"
                            BorderThickness="1" 
                            BorderBrush="Black"    
                            ItemsSource="{Binding (local:Facade.Item).ActualUser.Groups,RelativeSource={RelativeSource Self}}" >
                                    <ItemsControl.ContextMenu>
                                        <ContextMenu>
                                            <MenuItem Header="Add to group" 
                                              Click="AddGroupMenu_Click"
                                              ItemsSource="{Binding (local:Facade.Item).ActualUser.GroupsNotAssigned,RelativeSource={RelativeSource Self}}"
                                            >
                                                <MenuItem.ItemTemplate>
                                                    <DataTemplate>
                                                        <TextBlock 
                                                        Text="{Binding Path=Group.Name}">

                                                        </TextBlock>
                                                    </DataTemplate>
                                                </MenuItem.ItemTemplate>
                                            </MenuItem>
                                        </ContextMenu>
                                    </ItemsControl.ContextMenu>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal" Visibility="{Binding Path=IsMember,Converter={x:Static local:Converters.Bool2VisibilityConverter}}">
                                                <StackPanel.ContextMenu>
                                                    <ContextMenu>
                                                        <MenuItem Header="Remove from Group" 
                                                          CommandParameter="{Binding}"
                                                          Command="{Binding (local:Facade.Item).RemoveGroupFromUserCommand,RelativeSource={RelativeSource Self}}"
                                                          />
                                                    </ContextMenu>
                                                </StackPanel.ContextMenu>
                                                <!--<Image Width="15" Height="15" Margin="5,0,0,0"  Source="pack://siteOfOrigin:,,,/Images/group.png"></Image>-->
                                                <Image Width="15" Height="15" Margin="5,0,0,0" Source="Images\group.png" />
                                                <TextBlock Margin="2" Text="{Binding Path=Group.Name, ValidatesOnExceptions=True}" >
                                                            <TextBlock.Style>
                                                                <Style TargetType="{x:Type TextBlock}">
                                                                    <Style.Triggers>
                                                                        <Trigger Property="IsMouseOver" Value="True">
                                                                            <Setter Property="Foreground" Value="Blue" />
                                                                        </Trigger>
                                                                    </Style.Triggers>
                                                                </Style>
                                                            </TextBlock.Style>
                                                </TextBlock>
                                            </StackPanel>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <WrapPanel Orientation="Horizontal"/>
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>

                                </ItemsControl>


                            </Expander>
                            <Expander x:Name="expUserTypePermission" Expanded="expUserTypePermission_Expanded"  DockPanel.Dock="Top" Header="Type Permissions" Margin="0,5,0,0" Padding="5" IsExpanded="True" BorderThickness="1" BorderBrush="Silver">
                                <DockPanel>
                                    <ListBox x:Name="lbUserTypePermissions" 
                                         DockPanel.Dock="Left" 
                                         Margin="0,0,5,0"                                 
                                         Width="250"
                                         BorderBrush="Black"
                                         MinHeight="200"
                                         BorderThickness="1"
                                         Background="White"                                    
                                         SelectedItem="{Binding Path=(local:Facade.Item).ActualType,RelativeSource={RelativeSource Self}}"
                                         ItemsSource="{Binding Path=(local:Facade.Item).SecurityFramework.Types,RelativeSource={RelativeSource Self}}" Loaded="lbUserTypePermissions_Loaded">
                                        <ListBox.ItemTemplate>
                                            <DataTemplate>
                                                <StackPanel>
                                                    <TextBlock x:Name="PART_Text" Text="{Binding Name}">

                                                    </TextBlock>
                                                </StackPanel>
                                                <DataTemplate.Triggers>
                                                    <DataTrigger Binding="{Binding Name}" Value="MLifter.DAL.DB.DbDictionaries">
                                                        <Setter TargetName="PART_Text" Property="Text" Value="learning modules - general settings"/>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Name}" Value="MLifter.DAL.DB.DbDictionary">
                                                        <Setter TargetName="PART_Text" Property="Text" Value="learning module - specific settings"/>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Name}" Value="MLifter.DAL.DB.DbChapters">
                                                        <Setter TargetName="PART_Text" Property="Text" Value="chapters - general settings"/>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Name}" Value="MLifter.DAL.DB.DbChapter">
                                                        <Setter TargetName="PART_Text" Property="Text" Value="chapter - specific settings"/>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Name}" Value="MLifter.DAL.DB.DbCards">
                                                        <Setter TargetName="PART_Text" Property="Text" Value="cards - general settings"/>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Name}" Value="MLifter.DAL.DB.DbCard">
                                                        <Setter TargetName="PART_Text" Property="Text" Value="card - specific settings"/>
                                                    </DataTrigger>
                                                </DataTemplate.Triggers>
                                            </DataTemplate>
                                        </ListBox.ItemTemplate>
                                    </ListBox>
                                    <ContentPresenter x:Name="permissionsPresenter" Content="{Binding Path=(local:Facade.Item).ActualTypePermissionInformation,RelativeSource={RelativeSource Self}}"/>

                                </DockPanel>
                            </Expander>
                            <Expander x:Name="expUserObjectPermission" Expanded="expUserObjectPermission_Expanded" DockPanel.Dock="Top" Header="Object Permissions" Margin="0,5,0,0" Padding="5"  IsExpanded="False" BorderThickness="1" BorderBrush="Silver">
                                <DockPanel>

                                    <TreeView DockPanel.Dock="Left" 
                                     Margin="0,0,5,0"
                                     BorderBrush="Black"
                                     MinHeight="40"
                                     BorderThickness="1"
                                     Background="White"
                                     Width="250"
                                     SelectedItemChanged="TreeView_SelectedItemChanged" 
                                     ItemsSource="{Binding Path=(local:Facade.Item).Dictionaries,RelativeSource={RelativeSource Self}}" Name="tvUsersObjectPermissions" />
                                    <ContentPresenter x:Name="objectPermissionsPresenter" Content="{Binding Path=(local:Facade.Item).ActualObjectPermissionInformation,RelativeSource={RelativeSource Self}}"/>
                                </DockPanel>
                            </Expander>
                            <ContentControl></ContentControl>
                        </DockPanel>
                    </ScrollViewer>
                </DockPanel>
            </TabItem>
            <TabItem Header="Authentication Settings">
                <dialogs:AuthenticationSettingsEditor x:Name="authSettingsControl" HorizontalAlignment="Stretch" Width="Auto" Height="Auto"/>
            </TabItem>
            <TabItem Header="Sessions">
                <dialogs:Sessions x:Name="sessionsControl" HorizontalAlignment="Stretch" Width="Auto" Height="Auto"/>
            </TabItem>
        </TabControl>
    </Grid>
</Window>
